package com.shrw.duke.serialport.common.enity;

/**
 * Created by rw-duke on 2018/1/18.
 */

public class BaseLabelEnity {
    protected String head = "02030405";
    protected String length;
    protected String devId = "00000058";
    protected String cmd;
    protected String sn = "01";
    protected String encryption = "00";
    protected String checkSum = "00";

    public StringBuilder instruction;

    public BaseLabelEnity() {
        instruction = new StringBuilder();
    }

    public String getHead() {
        return head;
    }

    public void setHead(String head) {
        this.head = head;
    }

    public String getLength() {
        return length;
    }

    public void setLength(String length) {
        this.length = length;
    }

    public String getDevId() {
        return devId;
    }

    public void setDevId(String devId) {
        this.devId = devId;
    }

    public String getCmd() {
        return cmd;
    }

    public void setCmd(String cmd) {
        this.cmd = cmd;
    }

    public String getSn() {
        return sn;
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    public String getEncryption() {
        return encryption;
    }

    public void setEncryption(String encryption) {
        this.encryption = encryption;
    }

    public String getCheckSum() {
        return checkSum;
    }

    public void setCheckSum(String checkSum) {
        this.checkSum = checkSum;
    }

    /**
     * 解析指令
     *
     * @param instruction 16进制的指令
     */
    public void parse(String instruction) {
        if (instruction == null && instruction == "")
            return;
        this.instruction = new StringBuilder(instruction);
        head = instruction.substring(0, 8);
        length = instruction.substring(8, 12);
        devId = instruction.substring(12, 20);
//        cmd = instruction.substring(20,22);
        sn = instruction.substring(22, 24);
        encryption = instruction.substring(24, 26);
//        checkSum = instruction.substring(instruction.length()-2);
    }
}
